package b1.scenes.home.picpane
{
	import b1.players.*;
	
	import flash.display.Sprite;

	public class PlayerPicSwitcher extends Sprite
	{
		private const playerPaneX1:int = 5;
		private const playerPaneY1:int = 5;
		private const playerPaneX2:int = 5;
		private const playerPaneY2:int = 90;
		private var playerPane:PlayerPicPane;
		private var friendPane:PlayerPicPane;

		public function PlayerPicSwitcher()
		{
			super();
			var player:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			playerPane = new PlayerPicPane(player);
			playerPane.x = playerPaneX1;
			playerPane.y = playerPaneY1;
			addChild(playerPane);
		}
		
		public function switchPlayer(newPlayer:PlayerInfo):void
		{
			if (newPlayer.id != PlayerInfoHelper.getInstance().userId)
			{
				if (friendPane == null || friendPane.playerInfo.id != newPlayer.id)
				{
					if (friendPane != null && friendPane.parent != null)
						friendPane.parent.removeChild(friendPane);
					friendPane = new PlayerPicPane(newPlayer);
					friendPane.x = playerPaneX1;
					friendPane.y = playerPaneY1;
					playerPane.x = playerPaneX2;
					playerPane.y = playerPaneY2;
					addChild(friendPane);
				}
			}
			else
			{
				if (friendPane != null)
				{
					if (friendPane.parent != null)
					{
						friendPane.parent.removeChild(friendPane);
						friendPane = null;
					}
					playerPane.x = playerPaneX1;
					playerPane.y = playerPaneY1;
				}
			}
		}
		
	}
}